#coding:utf-8
from homeapp.models import TTest
# import uuid

class tnote_dal():

    @staticmethod
    def selectall():

        sql = "select homeapp_tnote.guid, homeapp_tnote.guid as mguid, Path, homeapp_tnotetype.guid, homeapp_tnotetype.guid as tguid, Text, TypeName from homeapp_tnote join homeapp_tnotetype on homeapp_tnote.NoteType_Guid = homeapp_tnotetype.guid;"
        # sql = "select homeapp_tnote.guid as mguid, homeapp_tnotetype.guid as tguid, Text, TypeName from homeapp_tnote join homeapp_tnotetype on homeapp_tnote.NoteType_Guid = homeapp_tnotetype.guid;"
        rset = TTest.objects.raw(sql)
        return rset

    @staticmethod
    def selectbyguids(guids):

        # 得到guids的个数
        guidcount = len(guids)
        zo = 0

        sql = "select homeapp_tnote.guid, homeapp_tnote.guid as mguid, Path, homeapp_tnotetype.guid, homeapp_tnotetype.guid as tguid, Text, TypeName from homeapp_tnote join homeapp_tnotetype on homeapp_tnote.NoteType_Guid = homeapp_tnotetype.guid where mguid in ("
        # sql = "select homeapp_tnote.guid as mguid, homeapp_tnotetype.guid as tguid, Text, TypeName from homeapp_tnote join homeapp_tnotetype on homeapp_tnote.NoteType_Guid = homeapp_tnotetype.guid;"
        for guid in guids:
            if zo == guidcount - 1:
                sql += "'" + guid + "')"
                zo += 1
            else:
                sql += "'" + guid + "',"
                zo += 1
        rset = TTest.objects.raw(sql)
        return rset

